import re
import json
import os
# 读取文本文件
def read_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
    
    # 使用正则表达式分割JSON对象
    pattern = re.compile(r'\{.*?\}', re.DOTALL)
    matches = pattern.findall(content)
    
    # 解析每个JSON对象
    emojis = []
    for match in matches:
        try:
            parsed = json.loads(match)
            emojis.append(parsed)
        except json.JSONDecodeError as e:
            print(f"解析错误: {e}")
            print(f"有问题的字符串: {match}")
    
    return emojis

# 转换为所需格式
def convert_to_format(emojis, base_dir):
    emoji_mapping = {}
    for emoji in emojis:
        name = emoji['name']
        origin_uri = f"{name}.png"
        local_path = os.path.join(base_dir, origin_uri)
        emoji_mapping[name] = local_path
    return emoji_mapping

# 主函数
def main():
    # 读取表情数据
    emojis = read_file('image_links.txt')
    
    # 转换为所需格式
    base_dir = "src/pic/emoji"
    emoji_mapping = convert_to_format(emojis, base_dir)
    
    # 打印结果
    for key, value in emoji_mapping.items():
        print(f"'{key}': '{value}',")

if __name__ == "__main__":
    main()